package cn.kailangtu.dataspot.data.context;

import android.widget.TextView;
import java.util.List;
import cn.kailangtu.commonevents.data.DataBean;
import cn.kailangtu.commontools.KeyboardUtils;
import cn.kailangtu.dataspot.data.ControlTreeNode;

public class KeyboardTargetContext {
    public static TextView keyboardTargetControl;
    public static ControlTreeNode controlTreeNode;
    public static String nuit;

    public static void clean(){
        keyboardTargetControl = null;
        nuit = "";
    }

    public static String getCurrentNumberValue()
    {
        String result = "";

        if(keyboardTargetControl != null)
        {
            String source = keyboardTargetControl.getText().toString();
            result = KeyboardUtils.getRealNumberValue(source);
            if(source.length()  != result.length())
            {
                nuit = source.substring(result.length());
            }
        }

        return result;
    }

   public static String  setNewNumberValue(String newValue)
   {

       if(nuit != null && nuit.length()>0)
       {
            newValue+=nuit;
       }
       if(keyboardTargetControl != null)
       {
           keyboardTargetControl.setText(newValue);
       }
       return newValue;
   }

   public static DataBean<Integer> getCurrentDataBean(List<DataBean<Integer>> collection)
   {

       DataBean<Integer> result = null;

       if(keyboardTargetControl != null && collection != null)
       {

           String title =  keyboardTargetControl.getText().toString();

           for(DataBean<Integer> item : collection)
           {
               if(item.getLabel().equals(title)) {
                   result = item;

                   break;
               }
           }
       }

       return result;
   }
}
